﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<select data-bind="options: availableAgents, 
                   optionsCaption:'Please select...',
                   optionsText: 'BusinessName',
                   optionsValue: 'Member_ID'
                   " class="validate[required] chz  hide" id="vmAgents" name="Agents">
</select>

<script type="text/javascript">
    $(document).ready(function() {
    //Begin Data
     var selected = "";
        <% if(Model.ToString()!=""){
         %>
            selected = <%=Model.ToString()%>;
         <%}  %>
    System.Data.AgentModel = function() {
        var self = this;
        //
        self.availableAgents = ko.observableArray([]);
        self.selected = ko.observableArray([]);

        (function() {
         $.getJSON(BASE_URL + "Listings/Ajax/GetAgents", function(result) {
            self.availableAgents(result.Data);

            $("#vmAgents").chosen({
                    allow_single_deselect: true
                });
                 if(selected !=""){
                           
                            $("#vmAgents").val(selected).trigger("liszt:updated");
                      }
                $("#vmAgents").removeClass("hide");
            });

        })();
    }
    //Fill Data
    var vmAgents = new System.Data.AgentModel();
    ko.applyBindings(vmAgents, $("#vmAgents")[0]);
    
});

</script>

